<?php
// +---------------------------------------------------------------------------+
// | This file is part of the KnowledgebasePublisher package                   |
// | KnowledgebasePublisher - web based knowledgebase publisher tool           |
// |                                                                           |
// | Author:  Evgeny Leontev <eleontev@gmail.com>                              |
// | Copyright (c) 2005 Evgeny Leontev                                         |
// |                                                                           |
// | For the full copyright and license information, please view the LICENSE   |
// | file that was distributed with this source code.                          |
// +---------------------------------------------------------------------------+

require_once 'core/app/AppMailSender.php';


class FeedbackView_form extends AppView
{
	
	var $template = 'form.html';
	
	
	function execute(&$obj, &$manager, $data) {
		
		$this->addMsg('letter_template_msg.ini');
		$this->addMsg('common_msg.ini', 'knowledgebase');
		
		$tpl = &new tplTemplatez($this->template_dir . $this->template);
		$tpl->tplAssign('error_msg', AppMsg::errorBox($obj->errors));
		
		$obj->set('question', nl2br($obj->get('question')));
		
		
		if($obj->get('user_id')) {
			$name = $data['first_name'] . ' ' . $data['last_name'];
			$tpl->tplAssign('first_name', $data['first_name']);
			$tpl->tplAssign('last_name', $data['last_name']);
			$tpl->tplAssign('username', $data['username']);
			$tpl->tplAssign('show_name', $name . ' - ' . $data['username']);
			$obj->set('name', $name);
		} else {
			$tpl->tplAssign('show_name', $obj->get('name'));
		}

		
		// attachment
		if($obj->get('attachment')) {
			$files = explode(';', $obj->get('attachment'));
			foreach($files as $k => $file) {
				$filename = basename($file);
				$link = $this->getActionLink('file', $obj->get('id'), array('f' => $k));
				$files[$k] = sprintf('<a href="%s">%s</a>', $link, $filename);
			}
			
			$tpl->tplAssign('files', implode('<br />', $files));
		}


		// answer
		$sender = &new AppMailSender();
		$sender->letter_key = 'answer_to_user';
		$parser = &$sender->parser;
		$parser->assign(array_merge($obj->get(), $data));	
		
		$obj->set('answer', $parser->parse($sender->getTemplate()));
				
		
		$tpl->tplAssign($this->setCommonFormVars($obj, '', $this->msg['answer_to_user_msg']));
		$tpl->tplAssign($obj->get());
		$tpl->tplAssign($this->msg);
		
		$tpl->tplParse();
		return $tpl->tplPrint(1);
	}
}
?>